/* GUI CONVERTED from woworcb.p (converter v1.76) Tue May  6 02:37:28 2003 */
/* woworcb.p - WORK ORDER RECEIPT SUBROUTINE TO CREATE REJECT TRANSACTION*/
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                   */
/* All rights reserved worldwide.  This is an unpublished work.          */
/* $Revision: 1.21 $                                              */
/*V8:ConvertMode=Maintenance                                             */
/* REVISION: 7.3        LAST MODIFIED: 03/25/93    BY: emb *G871*        */
/* REVISION: 7.3        LAST MODIFIED: 04/12/94    BY: pma *FN34*        */
/* REVISION: 7.3        LAST MODIFIED: 08/30/94    BY: pxd *FQ62*        */
/* REVISION: 7.3        LAST MODIFIED: 10/04/94    BY: pxd *FR90*        */
/* REVISION: 7.4        LAST MODIFIED: 01/24/95    BY: cpp *F0G1*        */
/* REVISION: 7.3        LAST MODIFIED: 12/19/95    BY: rvw *G1GN*        */
/* REVISION: 8.5        LAST MODIFIED: 09/30/95    BY: sxb *J053*        */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane     */
/* REVISION: 8.6E     LAST MODIFIED: 05/09/98   BY: *L00Y* Jeff Wootton  */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Vijaya Pakala */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KC* Mark Brown    */
/* REVISION: 9.1      LAST MODIFIED: 10/16/00   BY: *N0SX* Jean Miller   */
/* REVISION: 9.1      LAST MODIFIED: 11/06/00   BY: *N0TN* Jean Miller   */
/* Old ECO marker removed, but no ECO header exists *F0PN*               */
/* Revision: 1.14     BY: Katie Hilbert  DATE: 04/01/01 ECO: *P008*      */
/* Revision: 1.15     BY: Sathish Kumar  DATE: 06/05/01 ECO: *M199*      */
/* Revision: 1.16     BY: Niranjan R.  DATE: 07/23/01 ECO: *P00L*        */
/* Revision: 1.18     BY: Niranjan R.  DATE: 06/25/02 ECO: *P09L*        */
/* $Revision: 1.21 $    BY: Narathip W.  DATE: 04/19/03 ECO: *P0Q7*        */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}
{gplabel.i}
{cxcustom.i "WOWORCB.P"}

define input parameter pTrLot      like tr_lot    no-undo.

define new shared variable tr_recno as recid.
define new shared variable transtype as character initial "RCT-WO".

define shared variable newcst as decimal.
define shared variable rmks like tr_rmks.
define shared variable eff_date like glt_effdate.
define shared variable ref like glt_ref.
define shared variable wo_recno as recid.

define variable i as integer.
define variable cr_acct like wo_acct.
define variable cr_sub like wo_sub.
define variable cr_cc like wo_cc.
define variable gl_amt like glt_amt.
define variable glcost like sct_cst_tot.
define variable msgref like tr_msg.
define variable open_ref like mrp_qty.
define variable glx_mthd like cs_method.
define variable glx_set like cs_set.
define variable cur_mthd like cs_method.
define variable cur_set like cs_set.
define variable gl_tmp_amt as decimal no-undo.
define variable dftAcct       like pl_wip_acct no-undo.
define variable dftSubAcct    like pl_wip_sub  no-undo.
define variable dftCostCenter like pl_wip_cc   no-undo.
define variable l_wo_nbr like wo_nbr no-undo.
define variable l_wo_lot like wo_lot no-undo.
{&WOWORCB-P-TAG1}

/* PROCEDURE FOR ROUNDING FOR GIVEN ROUNDING METHOD */
{gpcrnd.i}
find first gl_ctrl no-lock.

find wo_mstr where recid(wo_mstr) = wo_recno no-lock no-error.
if not available wo_mstr then leave.

/* VARIABLES l_wo_nbr AND l_wo_lot ARE USED WHILE CREATING TR_HIST.           */
/* IF IT IS A FLOW ORDER THEN TR_LOT WILL HAVE NEW SEQUENCE NUMBER pTrLot AND */
/* TR_NBR WILL BE BLANK. FOR ALL OTHER TYPE OF WORK ORDERS TR_LOT WILL HAVE   */
/* WO_LOT AND TR_NBR  WILL HAVE WO_NBR */

if pTrLot <> " " and wo_type = "W" then
   assign
      l_wo_nbr = ""
      l_wo_lot = pTrLot.
else
   assign
      l_wo_nbr = wo_nbr
      l_wo_lot = wo_lot.

if wo_rjct_chg <> 0 then do:
   find wo_mstr where recid(wo_mstr) = wo_recno exclusive-lock.

   find pt_mstr no-lock where pt_part = wo_part.
   find pl_mstr where pl_prod_line = pt_prod_line no-lock.

   /*DETERMINE COSTING METHOD*/
   {gprun.i ""csavg01.p""
      "(wo_part,wo_site, output glx_set, output glx_mthd,
        output cur_set, output cur_mthd)" }
/*GUI*/ if global-beam-me-up then undo, leave.


   /******************************************************************/
   /*  (ON POSITIVE QUANTITY ORDERED)                                */
   /*      IF REAVG = NO, ISSUES SHOULD USE THE STANDARD COST        */
   /*      REJECTS, HOWEVER, SHOULD SCRAP THE CALCULATED COST        */
   /*      reavg_yn    wo_qty_ord      Receipt        Scrap          */
   /*      ========    ==========      ===========    ===========    */
   /*      Yes          > 0            newcst         newcst         */
   /*      Yes          < 0  ILLEGAL   -------        -------        */
   /*      No           > 0            sct_cst_tot    newcst         */
   /*      No           < 0            sct_cst_tot    sct_cst_tot    */
   /******************************************************************/
   {gpsct01.i &set=glx_set &part=pt_part &site=wo_site}
   if glx_mthd = "AVG"
      and wo_qty_ord >= 0
   then glcost = newcst.
   else glcost = sct_cst_tot - sct_ovh_tl.
   {gprun.i ""glactdft.p"" "(input ""WO_WIP_ACCT"",
                             input pt_prod_line,
                             input wo_site,
                             input """",
                             input """",
                             input no,
                             output dftAcct,
                             output dftSubAcct,
                             output dftCostCenter)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   /* CHANGED pl_wip_acct, pl_wip_sub and pl_wip_cc */
   /* TO dftAcct , dftSubAcct and dftCostCenter     */
   /* CHANGED ARGUMENTS &lotnumber = wo_lot AND &ordernbr = wo_nbr */
   /* TO &lotnumber = l_wo_lot AND &ordernbr = l_wo_nbr            */
   {ictrans.i
      &addrid=wo_vend
      &bdnstd=0
      &cracct="
         if wo_acct <> """" then
            wo_acct
         else
            dftAcct"
      &crsub="
         if wo_acct <> """" then
            wo_sub
         else
            dftSubAcct"
      &crcc="
         if wo_acct <> """" then
            wo_cc
         else
            dftCostCenter"
      &crproj="
         if wo_acct <> """" then
            wo_project
         else
            """""
      &curr=""""
      &dracct="
         if available pld_det then pld_scrpacct
         else pl_scrp_acct"
      &drsub="
         if available pld_det then pld_scrp_sub
         else pl_scrp_sub"
      &drcc="
         if available pld_det then pld_scrp_cc
         else pl_scrp_cc"
      &drproj="
          if wo_acct <> """" then
             wo_project
          else
              """""
      &effdate=eff_date
      &exrate=0
      &exrate2=0
      &exratetype=""""
      &exruseq=0
      &glamt="wo_rjct_chg * glcost"
      &lbrstd=0
      &line=0
      &location=""""
      &lotnumber=l_wo_lot
      &lotserial=""""
      &lotref=""""
      &mtlstd=0
      &ordernbr=l_wo_nbr
      &ovhstd=0
      &part=wo_part
      &perfdate=?
      &price=glcost
      &quantityreq=0
      &quantityshort=wo_rjct_chg
      &quantity=0
      &revision=""""
      &rmks=rmks
      &shiptype=""M""
      &site=wo_site
      &slspsn1=""""
      &slspsn2=""""
      &sojob=wo_so_job
      &substd=0
      &transtype=""RJCT-WO""
      &msg=0
      &ref_site=tr_site
      }

   {&WOWORCB-P-TAG2}
   /* UPDATE WORK ORDER */
   if max(wo_qty_ord
      - max(wo_qty_comp,0)
      - max(wo_qty_rjct,0),0) >= 0 then do:

      find in_mstr exclusive-lock where in_part = wo_part
         and in_site = wo_site no-error.

      if available in_mstr then do:
         if wo_qty_ord >= 0 then do:
            if wo_qty_ord - wo_qty_comp - wo_qty_rjct >= 0
               /* ADJUST BY LESSER OF REJECT QTY OR QTY OPEN */
            then
               in_qty_ord = in_qty_ord -
                  min(wo_rjct_chg,
                  max(wo_qty_ord - wo_qty_comp - wo_qty_rjct,0)).
            else
            if wo_qty_ord - wo_qty_comp - wo_qty_rjct - wo_rjct_chg  >= 0
            /* ADJUST BY REVERSING NET QUANTITY            */
            then
               in_qty_ord = in_qty_ord +
                  wo_qty_ord - wo_qty_comp - wo_qty_rjct - wo_rjct_chg.
         end.
         else do:
            if (wo_qty_ord - wo_qty_comp - wo_qty_rjct <= 0)
               /* ADJUST BY GREATER OF REJECT QTY OR QTY OPEN   */
            then
               in_qty_ord = in_qty_ord -
                  max(wo_rjct_chg,
                  min(wo_qty_ord - wo_qty_comp - wo_qty_rjct,0)).
            else
            if wo_qty_ord - wo_qty_comp - wo_qty_rjct - wo_rjct_chg  <= 0
               /* ADJUST BY REVERSING NET QUANTITY            */
            then
               in_qty_ord = in_qty_ord +
                  wo_qty_ord - wo_qty_comp - wo_qty_rjct -  wo_rjct_chg.
         end.
      end.
   end.

   /* ROUND PER BASE CURRENCY ROUND METHOD */
   run gpcrnd (input-output gl_amt, input gl_rnd_mthd).

   assign
      wo_qty_rjct = wo_qty_rjct + wo_rjct_chg
      wo_wip_tot  = wo_wip_tot - gl_tmp_amt
      wo_rjct_tot = wo_rjct_tot + gl_tmp_amt.

   if wo_qty_ord >= 0
   then
      open_ref = max(wo_qty_ord - max(wo_qty_comp,0) - max(wo_qty_rjct,0),0).
   else
      open_ref = min(wo_qty_ord - min(wo_qty_comp,0) - min(wo_qty_rjct,0),0).

   /* Replaced pre-processor with Term in include */
   {mfmrw.i "wo_mstr" wo_part wo_nbr wo_lot """"
      wo_rel_date wo_due_date open_ref "SUPPLY" WORK_ORDER wo_site}

   /* Replaced pre-processor with Term in include */
   {mfmrw.i "wo_scrap" wo_part wo_nbr wo_lot """"
      wo_rel_date wo_due_date "open_ref * (1 - wo_yield_pct / 100)"
      "DEMAND" SCRAP_REQUIREMENT wo_site}

end.
